using UnityEngine;

public class ShopItemPrefab : MonoBehaviour
{
	private ShopItemUI shopItemUI;

	public UISprite sprIcon;

	public UILabel lbName;

	public GameObject usingObject;

	[SerializeField]
	private ShopItemType showType;

	public Weapon weaponData;

	public PowerUp powerUpData;
	public UISprite selectedFrame;

	private bool isSelected = false;
	private ShopItemUI shopUI;
	public void SetSelected(bool selected)
	{
		isSelected = selected;
		//可以添加其他选中效果，比如缩放、边框等
		if (selected)
		{
			selectedFrame.gameObject.SetActive(true);
			transform.localScale = Vector3.one * 1.1f;
		}
		else
		{
			selectedFrame.gameObject.SetActive(false);
			transform.localScale = Vector3.one;
		}
	}
	public void SetItem(ShopItemUI shopItemUI, Weapon weaponData)
	{
		shopUI = shopItemUI;
		weaponData = weaponData;
		showType = ShopItemType.Weapon;
		this.shopItemUI = shopItemUI;
		this.weaponData = weaponData;
		lbName.text = weaponData.itemName;
		sprIcon.spriteName = weaponData.sprName;
		sprIcon.MakePixelPerfect();
		if (sprIcon.height > 35)
		{
			float value = 35f / (float)sprIcon.height;
			value = Mathf.Clamp(value, 0f, 0.5f);
			sprIcon.transform.localScale = new Vector3(-1f, 1f, 1f) * value;
		}
		UpdateShowItem();
		base.transform.localScale = Vector3.one;
		ShowUsing();
	}

	public void ShowUsing()
	{
		usingObject.SetActive(value: false);
	}

	public void SetItem(ShopItemUI shopItemUI, PowerUp powerUpData)
	{
		shopUI = shopItemUI;
		powerUpData = powerUpData;
		showType = ShopItemType.PowerUp;
		this.shopItemUI = shopItemUI;
		this.powerUpData = powerUpData;
		lbName.text = powerUpData.itemName;
		sprIcon.spriteName = powerUpData.sprName;
		sprIcon.MakePixelPerfect();
		sprIcon.transform.localScale = Vector3.one * 0.5f;
		UpdateShowItem();
		base.transform.localScale = Vector3.one;
		ShowUsing();
	}

	public void ClickItem()
	{
		shopUI.OnItemSelected(this);

		// 显示物品详情
		if (weaponData != null)
		{
			shopUI.ShowItemData(weaponData);
		}
		else if (powerUpData != null)
		{
			shopUI.ShowItemData(powerUpData);
		}
		switch (showType)
		{
			case ShopItemType.Weapon:
				shopItemUI.ShowItemData(weaponData);
				break;
			case ShopItemType.PowerUp:
				shopItemUI.ShowItemData(powerUpData);
				break;
		}
	}

	public void UpdateShowItem()
	{
		switch (showType)
		{
			case ShopItemType.Weapon:
				{
					bool flag = PersistenData.checkHasItem(weaponData.PrefKey);
					sprIcon.color = ((!flag) ? new Color(0f, 0f, 0f, 0.470588237f) : Color.black);
					break;
				}
			case ShopItemType.PowerUp:
				sprIcon.color = Color.white;
				break;
		}
	}
}
